﻿Imports Publics

Public Class FrmPhimTat
    Private lstSource As New List(Of clsPhimTat)

    Private Sub FrmPhimTat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            btnThemMoi.Caption = BtnAddNewCaption
            btnSuaDoi.Caption = BtnEditCaption
            btnXoa.Caption = BtnDeleteCaption
            btnNapLai.Caption = BtnRefreshCaption
            btnXuatDuLieu.Caption = BtnExportDataCaption
            btnThoat.Caption = BtnCancelCaption
            Me.Text = "Cài đặt phím tắt"
            FillDataToGrid()
            'Chi cho superadmin + admin sua phim tat thoi, khong cho ai sua het
            'If vUser.CanBo.UserName.ToLower = "superadmin" OrElse vUser.CanBo.UserName.ToLower = "admin" Then
            '    btnSuaDoi.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
            '    btnCaiDatMacDinh.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
            'Else
            '    btnSuaDoi.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
            '    btnCaiDatMacDinh.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
            'End If
        Catch ex As Exception
            MsgInfo(ex.Message)
        End Try
    End Sub

    Private Sub FillDataToGrid()
        ConnectToDB()
        Load_DMPhimTat()
        lstSource = (From ds In dbTV.SYS_PhimTats Where ds.InUsed _
                     Select New clsPhimTat(ds.ID, ds.TenNgan, ds.MaNut, ds.TenNut, ds.DienGiai, ds.KeyCode, ds.KeyFn, ds.Nhom)).ToList
        grdPhimTat.DataSource = lstSource
        grdPhimTat.RefreshDataSource()
        grvPhimTat.ExpandAllGroups()
    End Sub

    Private Sub btnThemMoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThemMoi.ItemClick
        Dim frm As New FrmCapNhatPhimTat
        frm.ActionForm = vAddAction
        frm.ShowDialog()
        FillDataToGrid()
    End Sub

    Private Sub btnSuaDoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSuaDoi.ItemClick
        Dim index = grvPhimTat.FocusedRowHandle
        Dim id = grvPhimTat.GetRowCellValue(grvPhimTat.FocusedRowHandle, "ID")
        If id IsNot Nothing AndAlso IsNumeric(id) Then
            Dim objData As SYS_PhimTat = (From ds In dbTV.SYS_PhimTats Where ds.InUsed And ds.ID = CInt(id)).FirstOrDefault
            If objData IsNot Nothing Then
                Dim frm As New FrmCapNhatPhimTat
                frm.ActionForm = vEditAction
                frm.PhimTat = objData
                frm.ShowDialog()
                FillDataToGrid()
                grvPhimTat.FocusedRowHandle = index
            End If
        End If
    End Sub

    Private Sub btnCaiDatMacDinh_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCaiDatMacDinh.ItemClick
        If MsgAskDelete("Bạn có muốn reset về phím tắt mặc định hay không?") = vMsg.vReSult.Yes Then
            clsDSPhimTatDefault.ResetToDefault()
            FillDataToGrid()
        End If
    End Sub

    Private Sub btnThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat.ItemClick
        Me.Close()
    End Sub

    Private Sub btnNapLai_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnNapLai.ItemClick
        FillDataToGrid()
    End Sub
End Class